Trò chơi Angry Birds trong UNITY Engine
31.687 lượt xem;
- EulerAnglesTweenProperty.cs
- specificTypes /
- properties /
- GoKit /
- Plugins /
- Assets /
- project /
1 using UnityEngine;
2 using System.Collections;
3
4
5 public class EulerAnglesTweenProperty : AbstractVector3TweenProperty
6 {
7 private bool _useLocalEulers;
8 public bool useLocalEulers { get { return _useLocalEulers; } }
9
10 public EulerAnglesTweenProperty( Vector3 endValue, bool isRelative = false, bool useLocalEulers = false ) : base( endValue, isRelative )
11 {
12 _useLocalEulers = useLocalEulers;
13 }
14
15
16 #region Object overrides
17
18 public override int GetHashCode()
19 {
20 return base.GetHashCode();
21 }
22
23
24 public override bool Equals( object obj )
25 {
26 // start with a base check and then compare if we are both using local values
27 if( base.Equals( obj ) )
28 return this._useLocalEulers == ((EulerAnglesTweenProperty)obj)._useLocalEulers;
29
30 // if we get here, we need to see if the other object is a rotation tween of the same kind
31 var otherAsRotation = obj as RotationTweenProperty;
32 if( otherAsRotation != null )
33 return this._useLocalEulers == otherAsRotation.useLocalRotation;
34
35 return false;
36 }
37
38 #endregion
39
40
41 public override void prepareForUse()
42 {
43 _target = _ownerTween.target as Transform;
44
45 _endValue = _originalEndValue;
46
47 // swap the start and end if this is a from tween
48 if( _ownerTween.isFrom )
49 {
50 _startValue = _endValue;
51
52 if( _useLocalEulers )
53 _endValue = _target.localEulerAngles;
54 else
55 _endValue = _target.eulerAngles;
56 }
57 else
58 {
59 if( _useLocalEulers )
60 _startValue = _target.localEulerAngles;
61 else
62 _startValue = _target.eulerAngles;
63 }
64
65 base.prepareForUse();
66 }
67
68
69 public override void tick( float totalElapsedTime )
70 {
71 var easedTime = _easeFunction( totalElapsedTime, 0, 1, _ownerTween.duration );
72 var vec = GoTweenUtils.unclampedVector3Lerp( _startValue, _diffValue, easedTime );
73
74 if( _useLocalEulers )
75 _target.localEulerAngles = vec;
76 else
77 _target.eulerAngles = vec;
78 }
79
80 }
2 using System.Collections;
3
4
5 public class EulerAnglesTweenProperty : AbstractVector3TweenProperty
6 {
7 private bool _useLocalEulers;
8 public bool useLocalEulers { get { return _useLocalEulers; } }
9
10 public EulerAnglesTweenProperty( Vector3 endValue, bool isRelative = false, bool useLocalEulers = false ) : base( endValue, isRelative )
11 {
12 _useLocalEulers = useLocalEulers;
13 }
14
15
16 #region Object overrides
17
18 public override int GetHashCode()
19 {
20 return base.GetHashCode();
21 }
22
23
24 public override bool Equals( object obj )
25 {
26 // start with a base check and then compare if we are both using local values
27 if( base.Equals( obj ) )
28 return this._useLocalEulers == ((EulerAnglesTweenProperty)obj)._useLocalEulers;
29
30 // if we get here, we need to see if the other object is a rotation tween of the same kind
31 var otherAsRotation = obj as RotationTweenProperty;
32 if( otherAsRotation != null )
33 return this._useLocalEulers == otherAsRotation.useLocalRotation;
34
35 return false;
36 }
37
38 #endregion
39
40
41 public override void prepareForUse()
42 {
43 _target = _ownerTween.target as Transform;
44
45 _endValue = _originalEndValue;
46
47 // swap the start and end if this is a from tween
48 if( _ownerTween.isFrom )
49 {
50 _startValue = _endValue;
51
52 if( _useLocalEulers )
53 _endValue = _target.localEulerAngles;
54 else
55 _endValue = _target.eulerAngles;
56 }
57 else
58 {
59 if( _useLocalEulers )
60 _startValue = _target.localEulerAngles;
61 else
62 _startValue = _target.eulerAngles;
63 }
64
65 base.prepareForUse();
66 }
67
68
69 public override void tick( float totalElapsedTime )
70 {
71 var easedTime = _easeFunction( totalElapsedTime, 0, 1, _ownerTween.duration );
72 var vec = GoTweenUtils.unclampedVector3Lerp( _startValue, _diffValue, easedTime );
73
74 if( _useLocalEulers )
75 _target.localEulerAngles = vec;
76 else
77 _target.eulerAngles = vec;
78 }
79
80 }